<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/22
 * Time: 11:49
 */
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Purse extends Model
{
    protected $table = 'fund_user_purse';

    /**
     * 获取钱包信息
     * @param $uid
     * @return mixed
     */
    public function wallet($uid)
    {
        // 金额
        $data = D('fund_user_purse as u')
            ->select('u.id','p.alias','p.name','u.balance','u.balancefreeze','u.pursetypeid as type','u.status')
            ->leftJoin('fund_purse_type as p','u.pursetypeid','=','p.id')
            ->where([['u.uid','=',$uid],['u.status','=',1],['u.pursetypeid','=',3]])
            ->get();
        $return = [];
        foreach ($data as $k => $v) {
            $data[$k]->uid = $uid;
            $data[$k]->balance = $v->balance/100;
            $data[$k]->balancefreeze = $v->balancefreeze/100;
            $data[$k]->available = $v->balance-$v->balancefreeze;
            $return[$v->alias] = $data[$k];
        }

        return $return;
    }
}